<?php
require_once('libraryfiles/config.php');
$table = Tblprovince::tblname;
$province = select($table);
if (!empty($_POST['txt_state'])) {
    $province_id = $_POST['txt_state'];
    $_SESSION['txt_state_id'] = $province_id;
    
    if (!empty($_POST['district'])) {
        $district = $_POST['district'];
        $long = $_POST['long'];
        $postcode = $_POST['postcode'];
        $khmer_name = $_POST['khmer_name'];
        $district_id = insert(Tblstate::tblname, array(
            Tblstate::name => addslashes($district),
            Tblstate::khmer_name => $khmer_name,
            Tblstate::zipcode => $postcode,
            Tblstate::lat_long => $long
        ));
        if ($district_id) {
            insert(Tblrefcode::tblname, array(
                Tblrefcode::name => 'district',
                Tblrefcode::type => 'district_state',
                Tblrefcode::value => $district_id,
                Tblrefcode::oject_id => $province_id
            ));
        }
    }
}
?>
<form method="post" class="form-horizontal">
    <div class="control-group">
        <label for="Phovince" class="control-label required"> Province <span class="required">*</span></label>
        <div class="controls">
            <input type="hidden" value="38" name="country_id"/>
            <select class="form_locate_province" name="txt_state" id="Phovince">
                <option value=""><?php echo $lang['SHIP_PRO_STATE']; ?></option>
                <?php
                $select = 'selected="selected"';
                $txtstate = (!empty($_SESSION['txt_state_id'])?$_SESSION['txt_state_id']:'');
                while ($result_pro = mysql_fetch_array($province)) {
                    ?>
                    <option <?php echo (($txtstate == $result_pro[Tblprovince::id]) ? $select : ''); ?> value="<?php echo $result_pro[Tblprovince::id]; ?>" data-id="<?php echo $result_pro[Tblprovince::lat_long]; ?>"><?php echo $result_pro[Tblprovince::name]; ?></option>
                <?php } ?>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="district"><!--Email--><?php echo $lang['UR_DISTRICT']; ?><?php //echo $var;   ?></label>
        <div class="controls">
            <input class="required" type="text" name="district" id="district" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="khmer_name">Khmer name</label>
        <div class="controls">
            <input class="required" type="text" name="khmer_name" id="khmer_name" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="postcode">Postal code</label>
        <div class="controls">
            <input class="required" type="text" name="postcode" id="postcode" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="long">location map</label>
        <div class="controls">
            <input class="required" type="text" name="long" id="long" />
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <input type="submit" name="submit" id="email" value="<?php echo $lang['SUBMIT']; ?>" />
        </div>
    </div>
</form>

